package com.cooba.adapter;


import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cooba.R;
import com.cooba.bean.DrawOutRecordBean;
import com.cooba.bean.IntegralDetailBean;

import java.util.List;

public class DrawOutRecordAdapter extends BaseAdapter {
    private Context context;
    private List<DrawOutRecordBean.DrawOutRecordInfo> list;

    public List<DrawOutRecordBean.DrawOutRecordInfo> getList() {
        return list;
    }

    public void setList(List<DrawOutRecordBean.DrawOutRecordInfo> list) {
        this.list = list;
        Log.d("wei", "" + list.size());
        this.notifyDataSetChanged();
    }

    public void addNewData(List<DrawOutRecordBean.DrawOutRecordInfo> datas) {
        if (datas != null && list != null) {
            this.list.addAll(0, datas);
            this.notifyDataSetChanged();
        }
    }

    public void addMoreData(List<DrawOutRecordBean.DrawOutRecordInfo> datas) {
        Log.d("wei", "" + datas.size() + "," + list.size());
        if (datas != null && list != null) {
            list.addAll(list.size(), datas);
            this.notifyDataSetChanged();
        }
    }

    public DrawOutRecordAdapter(Context context, List<DrawOutRecordBean.DrawOutRecordInfo> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list.size() == 0) {
            return 0;
        }
        return list.size();
    }

    @Override
    public DrawOutRecordBean.DrawOutRecordInfo getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.draw_out_record_list_item, parent, false);
            holder.draw_out_record_time = (TextView) convertView.findViewById(R.id.draw_out_record_item_time_tv);
            holder.draw_out_record_money = (TextView) convertView.findViewById(R.id.draw_out_record_item_money_tv);
            holder.draw_out_record_status1 = (TextView) convertView.findViewById(R.id.draw_out_record_item_status_tv);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();

        }

        holder.draw_out_record_time.setText(list.get(position).getTime().substring(2,16));
        holder.draw_out_record_money.setText(list.get(position).getMoney());
        //holder.draw_out_record_status.setText(list.get(position).getRemark());
        String status1=list.get(position).getStatus1();
        String temp = null;
        switch (Integer.parseInt(status1)){
            case 0:
                temp="提现审核中";
                holder.draw_out_record_status1.setTextColor(context.getResources().getColor(R.color.frame));
                break;
            case 1:
                temp="提现成功";
                holder.draw_out_record_status1.setTextColor(context.getResources().getColor(R.color.frame));
                break;
            case 2:
                temp="提现异常";
                holder.draw_out_record_status1.setTextColor(context.getResources().getColor(R.color.red));
                break;
            default:
                break;
        }
        holder.draw_out_record_status1.setText(temp);
        return convertView;
    }


    class ViewHolder {
        TextView draw_out_record_time;
        TextView draw_out_record_money;
        TextView draw_out_record_status1;


    }

}
